﻿using System;
using System.Collections.Generic;
using System.Text;

namespace PX.ExpertGain
{
	public class Component : Tony.ComponentBase
	{
		private Database clsDatabase = new Database();

		/// <summary>
		/// 构造函数
		/// </summary>
		public Component()
			: base()
		{
			listDatabaseEntity.Add(new Tony.DatabaseAndEntity("int", "nID", clsDatabase.ID));
			//listDatabaseEntity.Add(new Tony.DatabaseAndEntity("int", "nStatus", clsDatabase.STATUS));
			listDatabaseEntity.Add(new Tony.DatabaseAndEntity("int", "nExpertUserID", clsDatabase.EXPERTUSERID));
			listDatabaseEntity.Add(new Tony.DatabaseAndEntity("string", "strName", clsDatabase.NAME));
			listDatabaseEntity.Add(new Tony.DatabaseAndEntity("int", "nImageID", clsDatabase.IMAGEID));
			listDatabaseEntity.Add(new Tony.DatabaseAndEntity("string", "strContent", clsDatabase.CONTENT));
			listDatabaseEntity.Add(new Tony.DatabaseAndEntity("string", "strObtainDate", clsDatabase.OBTAINDATE));
			listDatabaseEntity.Add(new Tony.DatabaseAndEntity("string", "strDateTime", clsDatabase.DATETIME));
			listDatabaseEntity.Add(new Tony.DatabaseAndEntity("int", "nExpertDepartmentID", clsDatabase.EXPERTDEPARTMENTID));
			listDatabaseEntity.Add(new Tony.DatabaseAndEntity("int", "nUserID", clsDatabase.USERID));
			listDatabaseEntity.Add(new Tony.DatabaseAndEntity("int", "nFileContentID", clsDatabase.CONTENTFILECONTENTID));
		}

		#region 类型变换

		protected override Tony.EntityBase ConvertEntity()
		{
			//return base.ConvertEntity();
			Entity clsEntity = new Entity();

			return clsEntity;
		}

		protected override Tony.DataBase GetDataEntity()
		{
			//return base.GetDataEntity();
			return clsDatabase;
		}

		protected override Tony.QueryEntityBase GetQueryEntity()
		{
			//return base.GetQueryEntity();
			return new QueryEntity();
		}

		protected List<Entity> ConvertListEntityType(List<Tony.EntityBase> listBase)
		{
			List<Entity> list = new List<Entity>();

			for (int i = 0; i < listBase.Count; i++)
			{
				list.Add((Entity) listBase[i]);
			}

			return list;
		}

		#endregion

		protected override Tony.EntityBase DataToEntity(System.Data.DataRow dr)
		{
			Entity clsGain = new Entity();
			PX.User.UserComponent clsUserComp = new User.UserComponent();
			PX.User.User clsUser = new User.User();
			
			clsGain =(Entity) base.DataToEntity(dr);

			if (clsGain != null)
			{
				clsUser = clsUserComp.GetOne(clsGain.ExpertUserID);

				if (clsUser != null)
				{
					clsGain.ExpertName = clsUser.Name;
				}
			}

			return clsGain;
		}

		#region 查询

		/// <summary>
		/// 根据记录ID查询实体对象
		/// </summary>
		/// <param name="nID"></param>
		/// <returns></returns>
		public Entity QueryOneByID(int nID)
		{
			return (Entity)base.GetOneByID(nID);
		}

		/// <summary>
		/// 查询所有
		/// </summary>
		/// <returns></returns>
		public new List<Entity> QueryAll()
		{
			return ConvertListEntityType(base.QueryAll());
		}

		#endregion 查询
	}
}
